﻿<%@ WebHandler Language="C#" Class="SYS_Message_update" %>

using System;
using System.Web;
using System.Web.Script.Serialization;
using System.Collections.Generic;
using System.Web.SessionState;

public class SYS_Message_update : IHttpHandler, IRequiresSessionState
{
    sqlhelp sql = new sqlhelp();
    result result = new result();
    string str = "";
    System.Data.DataTable dt = new System.Data.DataTable();
    
    public void ProcessRequest (HttpContext context) {
        try
        {
            if (context.Session["comid"] == null)
            {
                result.code = "-1";
                result.msg = "用户未登录";
                unit.send(context, result);
                return;
            }

            string Id = "";
            string updateStr = "";
            if (context.Request["Id"] != null)
            {
                Id = context.Request["Id"].ToString();
            }
            else
            {
                result.code = "0";
                result.msg = "未传递商铺Id参数";
                unit.send(context, result);
                return;
            }

            System.Data.DataTable dtRecord = sql.myDataSet("select * from SYS_Message where Id = '" + Id + "'").Tables[0];
            if (dtRecord.Rows.Count == 0)
            {
                result.code = "0";
                result.msg = "无记录数据";
                unit.send(context, result);
                return;
            }



            string SubStance = "";
            if (context.Request["SubStance"] != null)
            {
                SubStance = context.Request["SubStance"].ToString();
                updateStr = updateStr + " SubStance = '" + SubStance + "',";
            }
            string Title = "";
            if (context.Request["Title"] != null)
            {
                Title = context.Request["Title"].ToString();
                updateStr = updateStr + " Title = '" + Title + "',";
            }
            string Url = "";
            if (context.Request["Url"] != null)
            {
                Url = context.Request["Url"].ToString();
                updateStr = updateStr + " Url = '" + Url + "',";
            }
            string ImageUrl = "";
            if (context.Request["ImageUrl"] != null)
            {
                ImageUrl = context.Request["ImageUrl"].ToString();
                //updateStr = updateStr + " ImageUrl = '" + ImageUrl + "',";
            }

            if (updateStr == "")
            {
                result.code = "0";
                result.msg = "未传递修改参数";
                unit.send(context, result);
                return;
            }

            updateStr = updateStr.TrimEnd(',');

            str = "update SYS_Message set " + updateStr + " where Id = '" + Id + "'";
            if (sql.ExecuteNonQuery(str) > 0)
            {
                if (ImageUrl != "") {
                    str = "update SYS_Image set Path = '" + ImageUrl + "' where Linkid = '" + dtRecord.Rows[0]["ImageUrl"].ToString() + "'";
                    sql.ExecuteNonQuery(str );
                }
                result.code = "1";
                result.msg = "";
            }
            else
            {
                result.code = "0";
                result.msg = "添加失败";
            }

        }
        catch (Exception e1)
        {
            result.code = "0";
            result.msg = e1.Message;
        }
        unit.send(context, result);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}